<template>
  <el-row id="feed">
    <el-form :inline="true">
      <el-form-item>
        <el-input v-model="feedbackTitleStr" size="small" placeholder="意见标题" style="vertical-align: top"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search" size="small" style="line-height:14px;vertical-align: top;">查询
        </el-button>
      </el-form-item>
    </el-form>
    <el-table :data="feedbackList" v-loading="listLoading" border style="width: 100%; font-size: 12px;" row-class-name="tabRow" tooltipEffect="light">
      <el-table-column align="center" prop="feedbackTitle" label="意见标题" show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="feedbackContent" label="意见内容" show-overflow-tooltip></el-table-column>
      <el-table-column align="center" prop="contact" label="联系方式"></el-table-column>
      <el-table-column align="center" :formatter="createTimeStr" label="创建时间"></el-table-column>
    </el-table>
    <el-col :span="24" class="toolbar" style="margin-top: 15px;" v-show="!listLoading">
      <el-pagination id="pagination" layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 30]"
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
      </el-pagination>
    </el-col>
  </el-row>
</template>

<script type="text/ecmascript-6">
  import {resetBreads, sessionOut} from '../../smartlight/common/js/util.js'
  export default{
    data () {
      return {
        total: 2,
        page: 1,
        pageSize: 10,
        feedbackList: [],
        listLoading: false,
        loginType: '',
        feedbackTitleStr: ''
      }
    },
    methods: {
      //      时间格式化
      createTimeStr (row, column) {
        var d = new Date(row.createTime)
        var year = d.getFullYear()
        var month = d.getMonth() + 1
        if (month < 10) {
          month = '0' + month
        }
        var date = d.getDate()
        if (date < 10) {
          date = '0' + date
        }
        var hh = d.getHours()
        if (hh < 10) {
          hh = '0' + hh
        }
        var mm = d.getMinutes()
        if (mm < 10) {
          mm = '0' + mm
        }
        var ss = d.getSeconds()
        if (ss < 10) {
          ss = '0' + ss
        }
        return year + '-' + month + '-' + date + ' ' + hh + ':' + mm + ':' + ss
      },
      search () {
        this.page = 1
        this.initFeedbackList()
      },
      // 分页插件查询方法-条数
      handleSizeChange (val) {
        this.pageSize = val
        this.initFeedbackList()
      },
      // 分页插件查询方法-页数
      handleCurrentChange (val) {
        this.page = val
        this.currentPage = val
        this.initFeedbackList()
      },
      initFeedbackList () {
        this.listLoading = true
        var para = {
          pageNumber: this.page,
          pageSize: this.pageSize,
          feedbackTitle: this.feedbackTitleStr.trim(),
          type: this.loginType
        }
        this.$http.post('/smartLight/web/feedback/getList.htm', para).then(response => {
          var resBody = response.body
          this.listLoading = false
          if (resBody.isSuccess === 0) {
            this.total = resBody.result.totalElements
            this.feedbackList = resBody.result.content
          } else if (resBody.isSuccess === 2) {
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      }
    },
    mounted () {
      var user = sessionStorage.getItem('user')
      resetBreads(this)
      if (user) {
        user = JSON.parse(user)
        this.loginType = user.type
        this.initFeedbackList()
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .is-light
    max-width: 600px;
  #feed
    .cell
      padding-left: 0px !important
      padding-right 0px !important
      overflow: hidden !important
      text-overflow: ellipsis !important
      white-space: nowrap !important
      .el-checkbox {
        padding-left: 15px !important
      }
</style>
